package com.mathplayer.js;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.JavaScriptObject;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class MathPlayerJS implements EntryPoint {
	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad() {
		initJavaScriptAPI();
	}
	
	private native void initJavaScriptAPI()/*-{
		var instance = this;
			
		$wnd.mathplayerCreateInstance = function(id,expression){
			return instance.@com.mathplayer.js.MathPlayerJS::createInstance(Ljava/lang/String;Ljava/lang/String;)(id, expression);
		}
		if(typeof $wnd.mathplayerOnAppLoaded == 'function') {
		  $wnd.mathplayerOnAppLoaded();	
		}
	}-*/;

	private JavaScriptObject createInstance(String id, String expression){
		MathPlayerController sc = new MathPlayerController(id, expression);
		return sc.getJavaScriptObject();
	}

}
